@ECHO OFF

SET INPUT=MakeFiles.lst
SET ROOTDIR=D:\Programming\Projects\ObjectLua
SET TARGETDIR=Build
SET OUTPUT=%ROOTDIR%\%TARGETDIR%

:CopyLoop
FOR /F "tokens=*" %%A in (%ROOTDIR%\%INPUT%) DO CALL :CheckFile %%A
GOTO :EOF

:CheckFile
SET SOURCE=%1
SET FILE=%~nx1
SET EXTENSION=%~x1
SET DIREXT=""

IF "%EXTENSION%"==".h" (
	CALL :CopyFile %SOURCE% incl
) ELSE (
	IF "%EXTENSION%"==".inl" (
		CALL :CopyFile %SOURCE% incl
	) ELSE (
		ECHO.%SOURCE%| FIND /I "x64">Nul && (
			CALL :CopyFile %SOURCE% lib\x64
		) || (
			CALL :CopyFile %SOURCE% lib\x86
		)
	)
)
GOTO :EOF

:CopyFile
SET SOURCE=%1
SET TARGET=%TARGETDIR%\%2\

ECHO Copying %SOURCE% to %TARGET%
XCOPY /Y "%ROOTDIR%\%SOURCE%" "%ROOTDIR%\%TARGET%"
ECHO.

GOTO :EOF